/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						      spellbook_window.h

	$Header: /game/spellbook_window.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef SPELLBOOK_WINDOW_H_INCLUDED
#define SPELLBOOK_WINDOW_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#pragma warning( disable: 4786 )

#include <vector>
#include "bitmap_group_ptr.h"
#include "bitmap_layer_ptr.h"
#include "button_group.h"
#include "game_window.h"

class t_cached_grail_data_source;
class t_artifact;
class t_artifact_icon;
enum  t_artifact_slot;
class t_bitmap_layer_window;
class t_button;
class t_abstract_creature;
enum  t_spell;
class t_spell_icon_window;
class t_spellbook_detail_window;
class t_text_window;
enum  t_town_type;
// -------------------------------------------------------------------
// window to display spells available in mage guild
// -------------------------------------------------------------------
struct t_spellbook_window_data
{
	t_spellbook_window_data( t_spell new_spell );
	t_spellbook_window_data( t_spell new_spell, int charge, int max_charge, t_artifact_slot slot );
	t_spellbook_window_data( t_spell new_spell, int charge, int max_charge, int backpack_slot );

	int				backpack_slot;
	bool			is_artifact;
	int				potion_count;
	t_artifact_slot slot;
	t_spell			spell;
	int				spell_points;
	int				max_spell_points;
};

class t_spell_tester
{
public:
	virtual bool operator()( t_spell spell ) const;
};

class t_spellbook_window : public t_window
{
public:
	enum t_open_mode { k_open_all, k_open_combat, k_open_adventure };

	t_spellbook_window( t_abstract_creature const* creature, t_window* parent, t_cached_grail_data_source const & grail_data, t_open_mode mode = k_open_all );

	void				     cast_spell_click( t_button*, 
		                                       t_spellbook_window_data const* spell );
	t_spellbook_window_data& get_selected_spell();
protected:
	void add_artifact( t_artifact const& artifact, t_artifact_slot slot, 
		               int backpack_slot, t_spell_tester const& valid_spell );
	void add_artifacts( t_spell_tester const& valid_spell );
	void add_spells( t_spell_tester const& valid_spell );
	void adventure_spells_click( t_button* );
	void all_spells_click( t_button* );
	void combat_spells_click( t_button* );
	void curses_click( t_button* );
	void blessings_click( t_button* );
	void close_click( t_button* );
	void create_buttons( t_screen_point origin );
	void create_labels( t_screen_point origin );
	void create_spell_icons( t_screen_point origin );
	void cycle_spell_tabs( bool reverse = false );
	void damage_spells_click( t_button* );
	void index_click( t_button* );
	void items_click( t_button* );
	void last_spell_click( t_button *);
	void next_spell_click( t_button *);
	void school_click( t_button*, t_town_type alignment );
	void scroll_spells( int first );
	void set_spell_type( char const* keyword );
	void spell_click( t_button*, int index );
	void summoning_click( t_button* );

	enum { 
		k_spell_rows	= 6,
		k_spell_columns = 2,
		k_total_spells	= k_spell_rows * k_spell_columns
	};
	struct t_spell_slot
	{
		t_button*               button;
		t_button*               information_button;
		t_spell_icon_window*	spell_window;
		t_artifact_icon*		artifact_window;
		t_text_window*			name;
		t_text_window*			cost;
		t_window*               window;
	};

	typedef std::vector<t_spellbook_window_data> t_spell_data_array;

	t_bitmap_group_ptr			m_book_bitmaps;
	int  						m_current_spell;
	t_abstract_creature const*	m_creature;
	t_spellbook_detail_window*	m_detail_window[2];
	int							m_first_spell;
	t_cached_grail_data_source const & m_grail_data;
	t_text_window*				m_header;
	std::string                 m_header_text;
	t_button*                   m_index_button;
	t_window*					m_index_window;
	t_button*					m_last_spell_button;
	t_button*					m_next_spell_button;
	t_spellbook_window_data     m_selected_spell;
	t_spell_slot				m_spell_slot[k_total_spells];
	t_bitmap_group_ptr          m_spell_type_icons;
	t_bitmap_layer_window*      m_spell_type_window;
	t_spell_data_array			m_spells;
	t_button_group				m_tab_buttons;
	t_bitmap_group_ptr			m_frame_bitmaps;
	t_bitmap_layer_window*		m_spell_icon_frame[k_total_spells];
	t_bitmap_layer_window*		m_charges[k_total_spells];
	t_bitmap_layer_window*		m_cost_background[k_total_spells];
	t_bitmap_layer_window*		m_name_background[k_total_spells];
	t_bitmap_layer_window*		m_detail_banner[2];
	t_text_window*				m_detail_spell_name[2];
	int							m_tab_index;
	bool						m_tab_valid[8];
};

inline t_spellbook_window_data& t_spellbook_window::get_selected_spell()
{
	return m_selected_spell;
}

#endif // MAGE_GUILD_WINDOW_H_INCLUDED